package cn.ml.io.liu;

import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

public class FileInputStreamDemo {
    public static void main(String[] args) {
        FileInputStream fis = null;
        //输入流FileInputStream
        try {
            fis = new FileInputStream("D:\\1_JAVA\\java_long\\basis\\src\\cn\\ml\\chuji\\io\\liu\\test.txt");
            System.out.println("可以读取到的字节数：" + fis.available());
            //111借助输入流的方法去读文件
            /*int date;
            while ((date=fis.read())!=-1){
                //System.out.print(date);  //此读取到字母所对应的数
                System.out.print((char) date);
            }*/
            //222借助输入流的read(byte[])方法去读文件
            byte[] b = new byte[1024];
            int date2;
            while ((date2 = fis.read(b)) != -1){
                for (int i = 0; i < date2; i++){
                    System.out.print((char) b[i]);
                }
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }finally {
            try {
                fis.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
